<template>
	<view class="swiper-list" :style="{height:`${height}px`}">
		<view class="list" :current="current" :style="{height:`${height}px`}" :vertical="true"
			:nextMargin="`${nextMarginHeight}px`"
			 :duration="300"
			>
			<view class="item">
				<view class="inner" @click="toDetail(product)">
					<view class="user-info" @click.stop="toUserInfo(product.user.uid)">
						<view class="avatar">
							<image class="img" :src="product.user.avatar||''" mode="widthFix"></image>
						</view>
						<view class="nickname">
							<view>{{product.user.nickname}}</view>
							<view>发布件数：{{product.user.publish_num}} 件</view>
						</view>
					</view>
					<swiper class="slider-image" autoplay indicator-dots circular :duration="500">
						<swiper-item v-for="(pic, i) in product.slider_image" :key="i">
							<image class="slider-pic" :src="pic" mode="aspectFill"></image>
						</swiper-item>
					</swiper>

					<view class="goods-item v-ellip-2">[{{product.id}}]{{product.store_name}}</view>

					<view class="goods-itembox">
						<view class="goods-item" v-if="product.cate_names">{{product.cate_names}}
							<text v-if="product.mType"><text class="separate">|</text>{{product.mType.title||""}}</text>
						</view>
						
						<view class="goods-item" v-if="product.stock">商品库存：<text class="color-desc">{{product.stock}}</text></view>
					</view>
					<view class="goods-itembox">
						<view class="goods-item color-red">￥{{product.price}}
							<text v-if="product.wear_txt" class="separate">|</text>{{product.wear_txt||""}} 
							<text v-if="product.made_at" class="separate">|</text>{{product.made_at||""}} 
						</view>
						<view class="goods-item" v-if="product.model">商品型号：<text class="color-desc">{{product.model}}</text></view>
					</view>

					
					<view class="goods-item" v-if="product.factory_name">生产厂家：<text class="color-desc">{{product.factory_name}}</text></view>
					<view class="goods-item" v-if="product.piece_no">商品件号：<text class="color-desc">{{product.piece_no}}</text></view>
					<view class="goods-item" v-if="product.intro">商品配置：<text class="color-desc">{{product.intro}}</text></view>
					<view class="goods-item" v-if="product.from_addr">发货地址：<text class="color-desc">{{product.from_addr}}</text></view>
					<view class="goods-item" v-if="product.store_info">描述文字：<text class="color-desc">{{product.store_info}}</text></view>
					<view class="goods-item" v-if="product.service_desc">售后描述：<text class="color-desc">{{product.service_desc}}</text></view>
				</view>
			</view>
			<view class="tuijian">
				<image class="tuijianicon" src="../../static/images/group02.gif" mode=""></image>
				为你推荐
			</view>
			<swiper-item class="item" :style="{height:`${height}px`}" v-for="(item, index) in list" :key="index">

				<view class="inner" @click="toDetail(item)">
					<view class="user-info" @click.stop="toUserInfo(item.user.uid)">
						<view class="avatar">
							<image class="img" :src="item.user.avatar||''" mode="widthFix"></image>
						</view>
						<view class="nickname">
							<view>{{item.user.nickname}}</view>
							<view>发布件数：{{item.user.publish_num}} 件</view>
						</view>
					</view>
					<swiper class="slider-image" autoplay indicator-dots circular :duration="500">
						<swiper-item v-for="(pic, i) in item.slider_image" :key="i">
							<image class="slider-pic" :src="pic" mode="aspectFill"></image>
						</swiper-item>
					</swiper>
					<view class="goods-item v-ellip-2">[{{item.id}}]{{item.store_name}}</view>
			<!-- 		<view class="goods-item color-red">￥{{item.price}} 
						<text v-if="item.wear_txt" class="separate">|</text>{{item.wear_txt||""}} 
						<text v-if="item.made_at" class="separate">|</text>{{item.made_at||""}} 
					</view> -->

					<view class="goods-itembox">
						<view class="goods-item" v-if="item.cate_names">{{item.cate_names}}
							<text v-if="item.mType"><text class="separate">|</text>{{item.mType.title||""}}</text>
						</view>
							<view class="goods-item" v-if="item.stock">商品库存：<text class="color-desc">{{item.stock}}</text></view>
					</view>
					<view class="goods-itembox">
						<view class="goods-item color-red">￥{{item.price}}
							<text v-if="item.wear_txt" class="separate">|</text>{{item.wear_txt||""}} 
							<text v-if="item.made_at" class="separate">|</text>{{item.made_at||""}} 
						</view>
							
							<view class="goods-item" v-if="item.model">商品型号：<text class="color-desc">{{item.model}}</text></view>
					</view>
		
					<!-- <view class="goods-item" v-if="item.stock">商品库存：<text class="color-desc">{{item.stock}}</text></view> -->
					<view class="goods-item" v-if="item.factory_name">生产厂家：<text class="color-desc">{{item.factory_name}}</text></view>
				
					<view class="goods-item" v-if="item.piece_no">商品件号：<text class="color-desc">{{item.piece_no}}</text></view>
					<view class="goods-item" v-if="item.intro">商品配置：<text class="color-desc">{{item.intro}}</text></view>
					<view class="goods-item" v-if="item.from_addr">发货地址：<text class="color-desc">{{item.from_addr}}</text></view>
					<view class="goods-item" v-if="item.store_info">描述文字：<text class="color-desc">{{item.store_info}}</text></view>
					<view class="goods-item" v-if="item.service_desc">售后描述：<text class="color-desc">{{item.service_desc}}</text></view>
				</view>
			</swiper-item><strong></strong>
			
			
		</view>
		<v-home></v-home>
	</view>
</template>

<script>
	let height = uni.getWindowInfo().windowHeight
	export default{
		data(){
			return {
				type: 0, // 列表类型：0推荐列表
				proid: 0,
				product: {},
				list: [],
				
				height: height,
				nextMarginHeight: height - height * 0.8 + 40,
				current: 0,
			}
		},
		onLoad(opts){
			this.type = parseInt(opts.type || 0)
			this.proid = parseInt(opts.id || 0)
			this.getProductById(()=>{
				this.init()
			})
		},
		methods:{
			toUserInfo(uid){
				this.$tool.navto(`/pages/other/user_info?uid=${uid}`);
			},
			init(){
				switch(this.type){
					case 0: // 推荐
						this.getRecommListExcludeId()
						break;
						
				}
			},
			getProductById(cb){
				this.$http.get("v1/getProductById/"+this.proid).then(res=>{
					this.product = res.data.product
					cb && cb()
				})
			},
			// 得到推荐商品列表（排除当前id）
			getRecommListExcludeId(){
				this.$http.get("v1/getRecommListExcludeId/"+this.proid).then(res=>{
					// this.list = [this.product, ...res.data.list]
					this.list = res.data.list
				})
			},
			toDetail(item){
				// var userinfo = JSON.stringify(item)
				let id = item.product_id || item.id
				// this.$tool.navto(`/pages/goods_details/index?id=${id}&userinfo=${userinfo}`);
				this.$tool.navto(`/pages/goods_details/index?id=${id}`);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.swiper-list{
		width: 100%;
		// overflow: hidden;
		box-sizing: border-box;
		// background-color: #282828;
		.list{
			.tuijian{
				font-size: 32rpx;
				color: #000;
				text-align: center;
				margin: 30rpx 0 0rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				.tuijianicon{
					width: 38rpx;
					height: 38rpx;
					margin-right: 10rpx;
				}
				
			}
			.item{
				display: flex;
				justify-content: center;

				.inner{
					// width: calc(100% - 40px);
					width: 100%;
					margin-top: 20px;
					border-radius: 10px;
					padding: 25rpx;
					background-color: #fff;
					.slider-image{
						height: calc(750rpx - 50px);
						.slider-pic{
							width: 100%;
							height: 100%;
							border-radius: 10px;
						}
					}
					.goods-itembox{
						display: flex;
						align-items: center;
						justify-content: space-between;
					}
					.goods-item{
						margin-top: 10rpx;
						.separate{
							margin: 0 10rpx;
						}
					}
					.user-info{
						display: flex;
						align-items: center;
						margin-bottom: 10rpx;
						.avatar{
							width: 10%;
							.img{
								width: 100%;
								border-radius: 50%;
							}
						}
						.nickname{
							display: flex;
							flex-direction: column;
							// align-items: center;
							margin-left: 10rpx;
						}
					}
				}
			}
		}
	}
</style>